<template>
	<view>
		<view style="display: flex;">
			<uni-list :border="false" style="width: 30%;">
				<uni-list-item :border="false" title="真实姓名"></uni-list-item>
				<uni-list-item :border="false" title="手机号码"></uni-list-item>
				<uni-list-item :border="false" title="邮箱"></uni-list-item>
				<uni-list-item :border="false" title="性别"></uni-list-item>
			</uni-list>
			<uni-list :border="false" style="width: 70%; margin-top: -4px;">
				<uni-list-item :border="false">
					<view slot="header" class="slot-box"><input v-model="from.nickName" placeholder="请输入真实姓名"
							type="text" /></view>
				</uni-list-item>
				<uni-list-item :border="false">
					<view slot="header" class="slot-box"><input v-model="from.phonenumber" placeholder="手机号码"
							type="text" /></view>
				</uni-list-item>
				<uni-list-item :border="false">
					<view slot="header" class="slot-box"><input v-model="from.email" placeholder="邮箱" type="text" />
					</view>
				</uni-list-item :border="false">
				<uni-list-item :border="false">
					<view slot="header" class="slot-box">
						<label>
							<radio type="radio" @click="changeSex('0')" :checked="from.sex==='0'" name="sex"
								value="0" />男
						</label>
						<label>
							<radio type="radio" @click="changeSex('1')" :checked="from.sex==='1'" name="sex"
								value="1" />女
						</label>
					</view>
				</uni-list-item>
			</uni-list>
		</view>
		<view>
			<button type="primary" @click="submitInfo" plain="true">修改</button>
		</view>

	</view>
</template>

<script>
	import {updateUser,getUser} from "../../api/login.js"
	
	export default {
		data() {
			return {
				from: {
					sex: '0',
					userId: 0,
					phonenumber: '',
					nickName: '',
					email: '',
					userName:""
				}
			}
		},
		onLoad() {
			this.getUserInfo();
		},
		methods: {
			changeSex(sex) {
				this.from.sex = sex;
			},
			submitInfo() {
				const data = this.from;
				console.log(data);
				updateUser(data).then(res=>{
					console.log(res);
					if(res.code===200){
						uni.showToast({
							title:"修改成功",
						})
						uni.removeStorage({
							key:'userInfo'
						})
						this.getUserInfo();
					}
				})
				
			},
			getUserInfo() {
				uni.getStorage({
					key: "userInfo",
					success: (res) => {
						getUser(res.data.userId).then(res=>{
							console.log(res);
							this.from.sex = res.data.sex;
							this.from.userId = res.data.userId;
							this.from.phonenumber = res.data.phonenumber;
							this.from.nickName = res.data.nickName;
							this.from.email = res.data.email;
							this.from.userName = res.data.userName;
							uni.setStorage({
								key:'userInfo',
								data:res.data
							})
						})
					}
				})
			}
		}

	}
</script>

<style>

</style>
